# Classification tree
library(mlr3)
library(tidyverse)

rm(list = ls())

# Load data ----
data(biopsy, package = "MASS")

str(biopsy)
biopsy <- biopsy %>% select(-ID)
names(biopsy) <- c("thick", "u.size", "u.shape", "adhsn", "s.size", "nucl",
                   "chrom", "n.nuc", "mit", "class")

bp <- na.omit(biopsy)

# Create model ----
bp.tsk <- TaskClassif$new(id = "biopsy", backend = bp, target = 'class')

mlr_learners
bp.lrn <- lrn("classif.rpart", id = "biopsy.rpart", predict_type = "prob")

bp.lrn$train(bp.tsk)
bp.pred <- bp.lrn$predict(bp.tsk)

bp.pred$score()
bp.pred$confusion

print(bp.lrn$model)
library(rpart.plot)
prp(bp.lrn$model)

bp.lrn$model$cptable
